package com.hw.one.peach.core.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hw.one.dam2.common.DamConstant;
import com.hw.one.dam2.common.SiteTypeEnum;
import com.hw.one.dam2.dao.IPatrolDeviceDao;
import com.hw.one.dam2.dao.IPatrolTrackDao;
import com.hw.one.dam2.dao.IRegionSiteDao;
import com.hw.one.dam2.dao.ISiteAirDao;
import com.hw.one.dam2.param.MovingDeviceParam;
import com.hw.one.dam2.param.RegionSiteParam;
import com.hw.one.dam2.param.SiteAirParam;
import com.hw.one.dam2.po.PatrolDataPo;
import com.hw.one.dam2.po.SiteAirQualityPO;
import com.hw.one.dam2.service.CityAirService;
import com.hw.one.dam2.service.IIndustryPollutionService;
import com.hw.one.dam2.util.CalendarUtil;
import com.hw.one.dam2.util.MathCalculateUtil;
import com.hw.one.dam2.util.WeatherUtil;
import com.hw.one.peach.core.dao.IRaiseDustDao;
import com.hw.one.peach.core.po.Point;
import com.hw.one.peach.core.po.RaiseDustPO;
import com.hw.one.peach.core.util.MovingSourceUtil;
import com.hw.one.peach.core.util.PointCalUtil;
import com.hw.one.util.DateTimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import javax.annotation.meta.Exclusive;
import java.text.DecimalFormat;
import java.util.*;

/**
 * Created by Administrator on 2017/8/4.
 */
@Service(value = "siteDataService")
public class SiteDataService implements ISiteDataService{


    @Autowired
    private ISiteAirDao siteAirDao;

    @Autowired
    private IRaiseDustDao raiseDustDao;

    @Resource
    private IRegionSiteDao regionSiteDao;

    @Resource
    private IIndustryPollutionService industryPollutionService;

    @Resource
    private IPatrolTrackDao patrolTrackDao;

    @Resource
    private IPatrolDeviceDao patrolDeviceDao;


    private static DecimalFormat df_3 = new DecimalFormat("#######.###############");
    @Override
    public Map<String, Object> findAirSiteLastDetailListBySiteTypeForTrend(Map<String, Object> paraMap) {
        /**
         * 国控点 nationalSite 省控点 provinceSite 小型站 smallAirSite 工业源 industrySite
         * 扬尘 raiseDustSite 油烟 lampblackSite 喷漆房 sprayBoothSite 加油站
         * gasStationSite 所有标准站 allNationalSite 所有空气站 allAirSite 所有污染源
         * allPollutionSite 所有站点 allSite
         *
         * 城市 citySite
         */
        String siteType = paraMap.get("siteType").toString();
        // 点位编码
        String siteCode = paraMap.get("siteCode").toString();

        List<Map<String, Object>> siteHourList = new ArrayList<>();
        // 国控站、省控站 小型站
        if (SiteTypeEnum.NATIONAL_SITE.getValue().equals(siteType)
                || SiteTypeEnum.PROVINCE_SITE.getValue().equals(siteType)
                || SiteTypeEnum.CITY_SITE.getValue().equals(siteType)
                || SiteTypeEnum.SMALL_AIR_SITE.getValue().equals(siteType)) {
            SiteAirParam siteAirParam = new SiteAirParam();
            List<String> siteCodeList = new ArrayList<>();
            siteCodeList.add(siteCode);
            siteAirParam.setSiteCodes(siteCodeList);
            // 查询两个小时前的分钟数据
            Calendar calendar = Calendar.getInstance();
            String endTime = CalendarUtil.getDateFormat(calendar.getTime(), DamConstant.SDF_YMD_HMS);
            calendar.add(Calendar.HOUR, -2);
            String startTime = CalendarUtil.getDateFormat(calendar.getTime(), DamConstant.SDF_YMD_HMS);
            siteAirParam.setStartTime(startTime);
            siteAirParam.setEndTime(endTime);
//            List<SiteAirQualityPO> gpointHourList = siteAirDao.findSiteAirHour12DataBySiteCode(siteAirParam);
            List<SiteAirQualityPO> minDataList = siteAirDao.findSiteAirMinDataBySiteCodesAndTime(siteAirParam);
            Collections.reverse(minDataList);
            dealGPointAqiData(minDataList, siteHourList);
        }else if(SiteTypeEnum.RAISE_DUST_NEW_SITE.getValue().equals(siteType)){

            SiteAirParam siteAirParam = new SiteAirParam();
            siteAirParam.setSiteCode(siteCode);
            // 2个小时前数据
            Calendar calendar = Calendar.getInstance();
            String endTime = CalendarUtil.getDateFormat(calendar.getTime(), DamConstant.SDF_YMD_HMS);
            calendar.add(Calendar.HOUR, -12);
            String startTime = CalendarUtil.getDateFormat(calendar.getTime(), DamConstant.SDF_YMD_HMS);
            siteAirParam.setStartTime(startTime);
            siteAirParam.setEndTime(endTime);
            // 新的扬尘数据
            List<RaiseDustPO> raiseDustPOList = raiseDustDao.findRaiseDustDataBySiteAndTime(siteAirParam);
            Collections.reverse(raiseDustPOList);
            dealRaiseDustData(raiseDustPOList, siteHourList);
        }

        List<String> aqiList = new ArrayList<String>();
        List<String> pm10List = new ArrayList<String>();
        List<String> pm25List = new ArrayList<String>();
        List<String> so2List = new ArrayList<String>();
        List<String> no2List = new ArrayList<String>();
        List<String> coList = new ArrayList<String>();
        List<String> o3List = new ArrayList<String>();
        List<String> monitorTimeList = new ArrayList<String>();
        for (Map<String, Object> dataMap : siteHourList) {
            Object monitorTimeObj = dataMap.get("monitorTime");
            if (null == monitorTimeObj || "".equals(monitorTimeObj)) {
                continue;
            }

            String monitorTime = monitorTimeObj.toString();
            // 时间格式化，把时间的秒去掉
            monitorTimeList.add(monitorTime.substring(0, 16));

            Object aqiObj = dataMap.get("aqi");
//            aqiObj = null == aqiObj || "".equals(aqiObj) ? "-" : aqiObj;
//            aqiList.add(aqiObj.toString());
            if (StringUtils.isEmpty(aqiObj) || !MathCalculateUtil.isInteger(aqiObj.toString()) || Integer.valueOf(aqiObj.toString()) < 0) {
                aqiList.add("-");
            }else {
                aqiList.add(aqiObj.toString());
            }

            Object pm10Obj = dataMap.get("pm10");
            pm10Obj = null == pm10Obj || "".equals(pm10Obj) ? "-" : pm10Obj;
            pm10List.add(pm10Obj.toString());

            Object pm25Obj = dataMap.get("pm25");
            pm25Obj = null == pm25Obj || "".equals(pm25Obj) ? "-" : pm25Obj;
            pm25List.add(pm25Obj.toString());

            Object so2Obj = dataMap.get("so2");
            so2Obj = null == so2Obj || "".equals(so2Obj) ? "-" : so2Obj;
            so2List.add(so2Obj.toString());

            Object no2Obj = dataMap.get("no2");
            no2Obj = null == no2Obj || "".equals(no2Obj) ? "-" : no2Obj;
            no2List.add(no2Obj.toString());

            Object coObj = dataMap.get("co");
            coObj = null == coObj || "".equals(coObj) ? "-" : coObj;
            coList.add(coObj.toString());

            Object o3Obj = dataMap.get("o3");
            o3Obj = null == o3Obj || "".equals(o3Obj) ? "-" : o3Obj;
            o3List.add(o3Obj.toString());
        }

        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.put("aqi", aqiList);
        dataMap.put("pm10", pm10List);
        dataMap.put("pm25", pm25List);
        dataMap.put("so2", so2List);
        dataMap.put("no2", no2List);
        dataMap.put("co", coList);
        dataMap.put("o3", o3List);
        dataMap.put("time", monitorTimeList);

        return dataMap;
    }

    @Override
    public Map<String, Object> findSiteDataBySelectBox(Map<String, Object> paramMap) throws Exception {

        String pointTypes = (String) paramMap.get("pointTypes");
        String regionCode = (String) paramMap.get("regionCode");
        String lngSets = (String) paramMap.get("lngSets");
        String latSets = (String) paramMap.get("latSets");

        // 所选区域框
        String[] latSet = latSets.split(",");
        String[] lngSet = lngSets.split(",");
        Point[] points = new Point[latSet.length];
        for (int i=0; i<latSet.length; i++) {
            points[i] = new Point(Double.valueOf(lngSet[i]), Double.valueOf(latSet[i]));
        }

        String[] pointTypeSet = pointTypes.split(",");
        // 如果传入类型是空，直接返回
        if (pointTypeSet.length < 1) {
            return new HashMap<>();
        }
        List<String> pointTypeList = Arrays.asList(pointTypeSet);

        Map<String, Object> resultMap = new HashMap<>();



        for (String pointType : pointTypeList) {
            List<Map<String, Object>> siteInfoList = new ArrayList<>();
            List<String> siteCodeList = new ArrayList<String>();
            if (SiteTypeEnum.INDUSTRY_SITE.getValue().equals(pointType) ||
                    SiteTypeEnum.RAISE_DUST_NEW_SITE.getValue().equals(pointType)) {
                RegionSiteParam siteParam = new RegionSiteParam();
                siteParam.setRegionCode(regionCode);  //当前用户的所在城市的区域编码
                siteParam.setSiteType(pointType);   //
                List<Map<String, Object>> siteInfoList2 = regionSiteDao.findSiteInfoByRegionCodeAndSiteType(siteParam);
                if (null == siteInfoList2 || siteInfoList2.size() == 0) {
                    resultMap.put(pointType, new ArrayList<>());
                    continue;
                }


                for (Map<String, Object> siteMap : siteInfoList2) {
                    double lng = Double.valueOf(String.valueOf(siteMap.get("Longitude")));
                    double lat = Double.valueOf(String.valueOf(siteMap.get("Latitude")));
                    // 判断站点是否在区域内
                    if (PointCalUtil.isPtInPoly(lng, lat, points)) {
                        siteCodeList.add(String.valueOf(siteMap.get("siteCode")));
                        siteInfoList.add(siteMap);
                    }
                }
                // 循环每一个类型
                if (siteCodeList.size() < 1) {
                    resultMap.put(pointType, new ArrayList<>());
                    continue;
                }
            }
            List<Map<String, Object>> returnList = null;
            //工业源
            if (SiteTypeEnum.INDUSTRY_SITE.getValue().equals(pointType)) {

                // 查询工业源 排口信息
                List<Map<String, Object>> outputInfoList = regionSiteDao.findIndustyOutputNameBySiteCode(siteCodeList);
                // 排口编号列表
                List<String> outputCodeList = new ArrayList<String>();
                for (Map<String, Object> outputMap : outputInfoList) {
                    outputCodeList.add(String.valueOf(outputMap.get("outputCode")));
                }

                List<Map<String, Object>> psList = industryPollutionService
                        .findPollutionNewHourDataByPSCodeAndOutputCodes(siteCodeList, outputCodeList);

                List<Map<String, Object>> pollutionList = new ArrayList<Map<String, Object>>();
                List<Map<String, Object>> pollutionEmptyList = new ArrayList<Map<String, Object>>();

                List<String> pollutionCodeList = new ArrayList<>();
                for (Map<String, Object> siteMap : siteInfoList) {
                    Object siteCodeObj = siteMap.get("siteCode");

                    for (Map<String, Object> dataMap : psList) {
                        Object psCode = dataMap.get("PSCode");
                        if (siteCodeObj.equals(psCode)) {
                            if (pollutionCodeList.contains(siteCodeObj)) {
                                continue;
                            }
                            pollutionCodeList.add(psCode.toString());
                            Object monitorTimeObj = dataMap.get("MONITORTIME");
                            if (null != monitorTimeObj && !"".equals(monitorTimeObj)) {
                                monitorTimeObj = String.valueOf(monitorTimeObj).substring(0, 16);
                            }
                            siteMap.put("monitorTime", monitorTimeObj);
                            siteMap.put("AvgStrength001", null == dataMap.get("AvgStrength001") || "".equals(dataMap.get("AvgStrength001")) ? "-" : dataMap.get("AvgStrength001"));
                            siteMap.put("AvgStrength002", dataMap.get("AvgStrength002"));
                            siteMap.put("AvgStrength003", dataMap.get("AvgStrength003"));
                            siteMap.put("AvgZsStrength003", dataMap.get("AvgZsStrength003"));
                            siteMap.put("AvgZsStrength002", dataMap.get("AvgZsStrength002"));
                            siteMap.put("AvgZsStrength001", dataMap.get("AvgZsStrength001"));
                            if (new CityAirService().isOrNotEmptyPollutionData(siteMap)) {
                                new CityAirService().dealPollutionMap(siteMap);
                                new CityAirService().putSiteStatus(siteMap, "0000"); // 数据为空值
                                pollutionEmptyList.add(siteMap);
                            } else {
                                new CityAirService().putSiteStatus(siteMap, "1111"); // 正常数据
                                pollutionList.add(siteMap);
                            }

                        }
                    }
                }
                pollutionList.addAll(pollutionEmptyList);
                // 根据AvgStrength001字段排序
                Collections.sort(pollutionList, new Comparator<Map>() {
                    @Override
                    public int compare(Map b1, Map b2) {
                        if ("-".equals(b1.get("AvgStrength001")) && "-".equals(b2.get("AvgStrength001"))) {
                            return 0;
                        }
                        if ("-".equals(b1.get("AvgStrength001"))) {
                            return 1;
                        }
                        if ("-".equals(b2.get("AvgStrength001"))) {
                            return -1;
                        }
                        Double one = Double.valueOf(b1.get("AvgStrength001").toString()) * 100;
                        Double two = Double.valueOf(b2.get("AvgStrength001").toString()) * 100;
                        return (int) (two - one);
                    }
                });
                for (Map<String, Object> siteInfo : siteInfoList) {
                    if (!pollutionCodeList.contains(String.valueOf(siteInfo.get("siteCode")))) {
                        new CityAirService().dealPollutionMap(siteInfo);
                        new CityAirService().putSiteStatus(siteInfo, "0001"); // 无记录数据
                        pollutionList.add(siteInfo);
                    }
                }
                returnList = pollutionList;
            }else if (SiteTypeEnum.RAISE_DUST_NEW_SITE.getValue().equals(pointType)) {
                // 循环每一个类型
                List<Map<String, Object>> raiseDustMapList = new ArrayList<>();
                List<Map<String, Object>> raiseDustNoDataMapList = new ArrayList<>();
                // 市建委扬尘数据
                SiteAirParam siteAirParam = new SiteAirParam();
                siteAirParam.setSiteCodes(siteCodeList);
                List<RaiseDustPO> raiseDustPOList = raiseDustDao.findRaiseDustRealDataBySiteCodes(siteAirParam);

                List<String> siteHaveDataList = new ArrayList<>();
                for (Map<String, Object> siteInfo : siteInfoList) {
                    boolean flag = false;
                    String siteCode = (String) siteInfo.get("siteCode");
                    if (siteHaveDataList.contains(siteCode)) {
                        continue;
                    }

                    for (RaiseDustPO raiseDustPO : raiseDustPOList) {
                        JSONObject hourPO = new JSONObject();
                        if (siteCode.equals(raiseDustPO.getSITECODE())) {

                            // 从数据库中读取的时间
                            String oragMonitorTime = raiseDustPO.getMONITORTIME2();
                            if (null != oragMonitorTime) {
                                hourPO.put("monitorTime", oragMonitorTime.substring(0, 16));
                            }
                            hourPO.put("siteName", siteInfo.get("siteName"));
                            hourPO.put("siteCode", siteInfo.get("siteCode"));
                            hourPO.put("siteTypeCode", siteInfo.get("siteTypeCode"));
                            hourPO.put("Latitude", siteInfo.get("Latitude"));
                            hourPO.put("Longitude", siteInfo.get("Longitude"));
                            hourPO.put("PM10", raiseDustPO.getPM10());
                            hourPO.put("PM2_5", raiseDustPO.getPM25());
                            hourPO.put("temp", raiseDustPO.getTEMP());
                            hourPO.put("hum", raiseDustPO.getHUM());
                            // 风速格式化成多少级
                            hourPO.put("windSpeed", WeatherUtil.changeWindSpeedToPowerNoCN(raiseDustPO.getWS()));
                            hourPO.put("windDirection", raiseDustPO.getWD());

                            if (!new RaiseDustDataService().isOrNotExceptionData(raiseDustPO)) {
                                siteHaveDataList.add(siteCode);
                                flag = true;
                                new RaiseDustDataService().putSiteStatus(hourPO, "1111"); // 数据正常
                                // 结果集
                                raiseDustMapList.add(hourPO);
                                break;
                            }
                        }
                    }
                    // 如果没有数据
                    if (!flag) {
                        Map<String, Object> hourPO = new HashMap<>();
                        hourPO.put("siteName", siteInfo.get("siteName"));
                        hourPO.put("siteCode", siteInfo.get("siteCode"));
                        hourPO.put("siteTypeCode", siteInfo.get("siteTypeCode"));
                        hourPO.put("Latitude", siteInfo.get("Latitude"));
                        hourPO.put("Longitude", siteInfo.get("Longitude"));
                        hourPO.put("PM10", "-");
                        hourPO.put("PM2_5", "-");
                        hourPO.put("temp", "-");
                        hourPO.put("hum", "-");
                        hourPO.put("monitorTime", "-");
                        // 风速格式化成多少级
                        hourPO.put("windSpeed", "-");
                        hourPO.put("windDirection", "-");
                        new RaiseDustDataService().putSiteStatus(hourPO, "0000"); // 数据异常
                        raiseDustNoDataMapList.add(hourPO);
                    }
                }
                String sortStr = "PM10";
                Collections.sort(raiseDustMapList, (a, b) -> {
                    if (null == a.get(sortStr) || "-".equals(String.valueOf(a.get(sortStr)))) {
                        return -1;
                    }
                    if (null == b.get(sortStr) || "-".equals(String.valueOf(b.get(sortStr)))) {
                        return -1;
                    }
                    Integer one = Integer.valueOf(a.get(sortStr).toString());
                    Integer two = Integer.valueOf(b.get(sortStr).toString());
                    return two.compareTo(one);
                });
                raiseDustMapList.addAll(raiseDustNoDataMapList);
                returnList = raiseDustMapList;
            }else if ("movingSource".equals(pointType)) {
                // 移动源
                Map<String, Object> searchMap = new HashMap<>();
                searchMap.put("regionCode", regionCode);
                searchMap.put("deviceType", "0"); // 查询全部的移动源
                // regionCode 必须，deviceType 必须
                List<Map<String, Object>> deviceInfoList = patrolDeviceDao.findPatrolDeviceInfoByRegionCode(searchMap);

                // 循环取出设备编码
                List<String> deviceCodeList = new ArrayList<>();
                Map<String,String> codeWithName = new HashMap<>();
                Map<String,String> codeWithCompanyName = new HashMap<>();
                Map<String,String> codeWithCarCode = new HashMap<>();
                Map<String,String> codeWithDeviceTypeCode = new HashMap<>();
                for (Map<String, Object> deviceInfo : deviceInfoList) {
                    deviceCodeList.add((String) deviceInfo.get("deviceCode"));
                    codeWithName.put((String) deviceInfo.get("deviceCode"), (String) deviceInfo.get("deviceName"));
                    codeWithCompanyName.put((String) deviceInfo.get("deviceCode"), (String) deviceInfo.get("companyName"));
                    codeWithCarCode.put((String) deviceInfo.get("deviceCode"), (String) deviceInfo.get("carCode"));
                    codeWithDeviceTypeCode.put((String) deviceInfo.get("deviceCode"), String.valueOf(deviceInfo.get("deviceType")));
                }

                MovingDeviceParam deviceParam = new MovingDeviceParam();
                deviceParam.setDeviceCodeList(deviceCodeList);
                List<double[]> locationList = new ArrayList<>();
                // 所选区域框
                for (int i=0; i<latSet.length; i++) {
                    double[] locations = new double[2];
                    String lng = lngSet[i];
                    String lat = latSet[i];
                    locations[0] = Double.valueOf(lng);
                    locations[1] = Double.valueOf(lat);
                    locationList.add(locations);
                }
                // 框选区域点位小于3返回空值
                if (locationList.size() > 2) {
                    deviceParam.setLocationList(locationList);
                    // 查询设备实时轨迹信息
                    List<PatrolDataPo> trackList = patrolTrackDao.findPatrolTrackRealDataByLocation(deviceParam);

                    // 循环数据，组装成前段需要的格式
                    // 判断是否在所选区域内
                    List<Map<String, Object>> returnArr = new ArrayList<>();
                    Date nowDate = CalendarUtil.getDateByString(CalendarUtil.getDateFormat(new Date(), DamConstant.ALL_SDF_YMD), DamConstant.ALL_SDF_YMD);
                    if (trackList != null && trackList.size() > 0) {
                        for (PatrolDataPo track : trackList) {
                            JSONObject obj = new JSONObject();
                            String deviceCode = track.getDEVICECODE();
                            String monitorTime = track.getMONITORTIME();
                            Date monitorDate = CalendarUtil.getDateByString(monitorTime, DamConstant.SDF_YMD_HMS);
                            // 判断时间比当前时间，如果小于今天00的时间，就认为不在线
                            String status;
                            if (monitorDate.getTime() > nowDate.getTime()) {
                                status = "1111"; // 数据正常
                            }else {
                                status = "0000"; // 数据异常
                            }
                            obj.put("siteStatus", status);
                            obj.put("deviceCode", deviceCode);
                            obj.put("deviceName", codeWithName.get(deviceCode));
                            obj.put("companyName", codeWithCompanyName.get(deviceCode));
                            obj.put("carCode", codeWithCarCode.get(deviceCode));
                            obj.put("lat",track.getLoc()[1]);
                            obj.put("lng",track.getLoc()[0]);
                            obj.put("deviceStatus",track.getDEVCIESTATUS() == null ? "-" : MovingSourceUtil.changeDeviceStatus(track.getDEVCIESTATUS()));
                            obj.put("runStatus",track.getRUNSTATUS() == null ? "-" : MovingSourceUtil.changeRunningStatus(track.getRUNSTATUS()));
                            obj.put("alarmStatus",track.getALARMSTATUS() == null ?"-" : MovingSourceUtil.changeAlarmStatus(track.getALARMSTATUS()));
                            String deviceTypeCode = codeWithDeviceTypeCode.get(deviceCode);
                            if ("4".equals(deviceTypeCode)) {
                                obj.put("deviceType", "渣土车");
                                obj.put("deviceTypeCode", "4");
                            }else {
                                obj.put("deviceType", "-");
                                obj.put("deviceTypeCode", "-");
                            }
                            returnArr.add(obj);
                        }
                    }
                    returnList = returnArr;
                }


            }
            resultMap.put(pointType, returnList);
        }
        return resultMap;
    }

    private void dealRaiseDustData(List<RaiseDustPO> raiseDustPOList, List<Map<String, Object>> mapList) {
        Map<String, Object> aqiMap = null;
        for (RaiseDustPO hourAirMap : raiseDustPOList) {
            aqiMap = new HashMap<String, Object>();
            aqiMap.put("pm10", hourAirMap.getPM10());

            aqiMap.put("pm25", hourAirMap.getPM25());

            aqiMap.put("siteCode", hourAirMap.getSITECODE());
            aqiMap.put("monitorTime", hourAirMap.getMONITORTIME2());

            aqiMap.put("temp", hourAirMap.getTEMP() == null ? "" : hourAirMap.getTEMP());
            aqiMap.put("hum", hourAirMap.getHUM() == null ? "" : hourAirMap.getHUM());
            aqiMap.put("windDirection", hourAirMap.getWD() == null ? "" : WeatherUtil.changeAngleToWindDirection(String.valueOf(hourAirMap.getWD())));
            aqiMap.put("windSpeed", hourAirMap.getWS() == null ? "" : WeatherUtil.changeWindSpeedToPower(String.valueOf(hourAirMap.getWS())));

            mapList.add(aqiMap);
        }
    }


    private void dealGPointAqiData(List<SiteAirQualityPO> gpointNewDataList, List<Map<String, Object>> aqiList) {
        Map<String, Object> aqiMap = null;
        for (SiteAirQualityPO hourAirMap : gpointNewDataList) {
            aqiMap = new HashMap<String, Object>();
            aqiMap.put("aqi", hourAirMap.getAQI() == null ? "0" : hourAirMap.getAQI());
            aqiMap.put("aqiLevel", hourAirMap.getAQILEVEL());
            aqiMap.put("aqiLevelType", hourAirMap.getAQILEVELTYPE());
            aqiMap.put("pollutant", hourAirMap.getPOLLUTANT());
            aqiMap.put("compositeValue", hourAirMap.getCOMPOSITEVALUE() == null ? "0" : hourAirMap.getCOMPOSITEVALUE());

            aqiMap.put("pm10", hourAirMap.getPM10().getCONCENTRATION());
            aqiMap.put("pm10IAQI", hourAirMap.getPM10().getIAQI());

            aqiMap.put("pm25", hourAirMap.getPM25().getCONCENTRATION());
            aqiMap.put("pm25IAQI", hourAirMap.getPM25().getIAQI());

            aqiMap.put("so2", hourAirMap.getSO2().getCONCENTRATION());
            aqiMap.put("so2IAQI", hourAirMap.getSO2().getIAQI());

            aqiMap.put("no2", hourAirMap.getNO2().getCONCENTRATION());
            aqiMap.put("no2IAQI", hourAirMap.getNO2().getIAQI());

            aqiMap.put("co", hourAirMap.getCO().getCONCENTRATION());
            aqiMap.put("coIAQI", hourAirMap.getCO().getIAQI());

            aqiMap.put("o3", hourAirMap.getO3().getCONCENTRATION());
            aqiMap.put("o3IAQI", hourAirMap.getO3().getIAQI());

            aqiMap.put("siteCode", hourAirMap.getSITECODE());
            aqiMap.put("monitorTime", hourAirMap.getMONITORTIME());

            aqiMap.put("temp", hourAirMap.getTEMP() == null ? "" : hourAirMap.getTEMP());
            aqiMap.put("hum", hourAirMap.getHUM() == null ? "" : hourAirMap.getHUM());
            aqiMap.put("windDirection", hourAirMap.getWD() == null ? "" : WeatherUtil.changeAngleToWindDirection(String.valueOf(hourAirMap.getWD())));
            aqiMap.put("windSpeed", hourAirMap.getWS() == null ? "" : WeatherUtil.changeWindSpeedToPower(String.valueOf(hourAirMap.getWS())));

            aqiList.add(aqiMap);
        }

    }
}
